<template>
	<!-- 新闻资讯 -->
	<view class="page">
		<view class="news-main" v-for="(tem,index) in newsList" :key="index" @click="gotoDetail(tem.id)">
			<view class="main-left">
				<view class="main-left-top">
					{{tem.title}}
				</view>
				<view class="main-left-b">
					<view class="main-title">{{tem.key}}</view>
					<view class="main-see">预览{{tem.point}}</view>
				</view>
			</view>
			<view class="main-right">
				<image :src="tem.pic"></image>
			</view>
		</view>
		 <uni-load-more :status="loadingType"></uni-load-more>
		 <uni-load-more v-if="newsList.length" :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import { secondmainNews } from '@/service/getData.js';
    import { mapState, mapMutations } from 'vuex';
	import { router, toast, localStorage, dateUtils } from '@/common/util.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
        components:{
			uniLoadMore
        },
		data() {
			return {
               newsList: [],
			   page: 1, //当前页
			   loadingType: 'more',
			};
		},
        computed: mapState(['hasLogin', 'screenTemp']),
         onLoad() {
            this.getnews('init');
        },
   //      onShow() {
			// this.getnews('init');
   //      },
   //      onHide() {

   //      },
        // onNavigationBarButtonTap() { // 标题栏按钮点击事件
        //     router.navigateTo('/pages/pallet/screen/screen');
        // },
		onPullDownRefresh() { // 下拉刷新
            this.getnews();
		},
        onReachBottom() { // 上拉触底
            this.getnews('ReachBottom');
        },
		methods: {
            ...mapMutations(['GOPAGE_LOGIN', 'SCREEN_TEMP']),

			getnews(type='DownRefresh'){
				if(type == 'DownRefresh'){
                    this.page = 1;
                    this.loadingType = 'more';
                    toast.loading();
                }
                if(type == 'ReachBottom'){
                    if(this.loadingType == 'noMore') return;
                    this.loadingType = 'loading';
                }
				let sent ={"type":"newslist","newtype":0,"page":this.page,"size":10};
				console.log("输出："+JSON.stringify(sent))
				secondmainNews({data:sent}).then(res => {
					let news = eval('('+res.data+')');
					// console.log("分页获取数据："+JSON.stringify(news[0].meslist))
					if(this.page == 1){
						this.newsList = news[0].meslist;
					}else{
					    this.newsList = this.newsList.concat(news[0].meslist);
					}
					 // console.log("获取数据："+JSON.stringify(this.newsList))
					if(type == 'DownRefresh'){
					    uni.stopPullDownRefresh();
					    toast.hideLoading();
					}
					let newsa = eval('('+res.data+')');
					if(newsa[0].meslist.length < 10){
					    this.loadingType = 'noMore';
					}else{
					    this.loadingType = 'more';
					    this.page ++;
					}
					
				})
			},
			gotoDetail(id){
				router.navigateTo('/pages/news/newsDetail/newsDetail?id='+id);
			}
			
        }
	}
</script>

<style lang="scss">
	@import '@/style/mixin/flex.scss';
	@import '@/style/mixin/hr.scss';
	@import '@/style/page/banner.scss';
	.page{
		margin: 0;
		padding: 0;
		.news-main{
			padding: 15upx 20upx;
			display: flex;
			flex-direction: row;
			background-color: #ffffff;
			margin-bottom: 5upx;
			.main-left{
				width: 70%;
				.main-left-top{
					font-size: 34upx;
					color: #000000;
				}
				.main-left-b{
					display: flex;
					flex-direction: row;
					margin-top: 20upx;
					margin-bottom: 10upx;
					.main-title{
						color: #ff6652;
						border: 1upx solid #ff6652;
						font-size: 26upx;
						padding: 0 3upx;
					}
					.main-see{
						margin-left: 30upx;
						color: #b6b6b6;
						font-size: 24upx;
					}
				}
			}
			.main-right{
				width: 26%;
				margin-left: 30upx;
				image{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
	

</style>
